/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller;

import com.thienloc.omap.controller.scatchcard.PartnerProduction;
import com.thienloc.omap.controller.scatchcard.PartnerRevenue;
import com.thienloc.omap.controller.scatchcard.TransactionResult;
import com.thienloc.omap.session.TransactionFacade;
import com.thienloc.omap.util.JsfUtil;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@ViewScoped
public class ScratchCardReportBean implements Serializable {

    @EJB
    private TransactionFacade transactionFacade;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private List<PartnerProduction> list;
    private List<PartnerRevenue> partnerRevenues;
    private List<TransactionResult> transactionResults;
    private String partnerId;
    private Date startTime;
    private Date endTime;
    private String startWindow;
    private String endWindow;

    @PostConstruct
    void init() {
        startTime = new Date();
        startTime.setHours(0);
        startTime.setMinutes(0);
        startTime.setSeconds(0);
        startTime.setMonth(startTime.getMonth() - 1);

        endTime = new Date();
        endTime.setHours(23);
        endTime.setMinutes(59);
        endTime.setSeconds(59);

        startWindow = "00:00:00";
        endWindow = "23:59:59";
    }

    public void getReport() {
        try {
            startTime.setHours(0);
            startTime.setMinutes(0);
            startTime.setSeconds(0);
            endTime.setHours(23);
            endTime.setMinutes(59);
            endTime.setSeconds(59);

            list = transactionFacade.find(partnerId, startTime, endTime, startWindow, endWindow);
            transactionResults = transactionFacade.getTransactionResultReport(partnerId, startTime, endTime, startWindow, endWindow);
            partnerRevenues = transactionFacade.getParnerRevenueReport(partnerId, startTime, endTime, startWindow, endWindow);
        } catch (Exception ex) {
            logger.error("", ex);
            JsfUtil.addErrorMessage("Error", ex.getMessage());
        }
    }

    public String getPartnerId() {
        return partnerId;
    }

    public void setPartnerId(String partnerId) {
        this.partnerId = partnerId;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public List<PartnerProduction> getList() {
        return list;
    }

    public List<PartnerRevenue> getPartnerRevenues() {
        return partnerRevenues;
    }

    public void setPartnerRevenues(List<PartnerRevenue> partnerRevenues) {
        this.partnerRevenues = partnerRevenues;
    }

    public List<TransactionResult> getTransactionResults() {
        return transactionResults;
    }

    public void setTransactionResults(List<TransactionResult> transactionResults) {
        this.transactionResults = transactionResults;
    }

    public String getStartWindow() {
        return startWindow;
    }

    public void setStartWindow(String startWindow) {
        this.startWindow = startWindow;
    }

    public String getEndWindow() {
        return endWindow;
    }

    public void setEndWindow(String endWindow) {
        this.endWindow = endWindow;
    }
}
